-
Notifications
You must be signed in to change notification settings - Fork 6
drpcmux: add support for server interceptors #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drpcmux: add support for server interceptors #10
Conversation
cthumuluru-crdb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a couple of minor comments. Otherwise the changes look good to me.
|
|
||
| type UnaryHandler func(ctx context.Context, in interface{}) (out interface{}, err error) | ||
|
|
||
| type UnaryServerInterceptor func( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comments and contract for the interceptors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| if currIdx == len(interceptors) { | ||
| return handler | ||
| } | ||
| return func(ctx context.Context, in interface{}) (out interface{}, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about extracting this into asUnaryHandler(i UnaryInterceptor) UnaryHandler function? I find it more readable and easy to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a bit more complicated. We're not just adapting the interceptor as a handler; we're also capturing arguments from getChainedUnaryHandler. This means if a method is declared as asUnaryHandler, it will still accept those arguments, making the cleanup pointless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are right. I would suggest adding a comment on what that code is meant to do for future reference.
| type StreamHandler func(ctx context.Context, in drpc.Stream) (out interface{}, err error) | ||
|
|
||
| type StreamServerInterceptor func( | ||
| ctx context.Context, stream drpc.Stream, rpc string, handler StreamHandler) (out interface{}, err error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like we discussed before, rpc string can be replaced with StreamServerInfo similar to gRPC. Since stream interceptors apply to all forms of stream RPCs (unary request + stream response, stream request + unary response, stream request + stream response), this metadata will be useful for writing an interceptor that only applies to one form of stream interceptor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of adding this, but I'm waiting to come across any use case where we need more than an RPC string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not necessarily suggesting to block on this but IMO interfaces should also help with future needs. I'm fine with the current approach and revisit it if needed.
3c6288c to
5d8e4dc
Compare
cthumuluru-crdb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thank you!
| if currIdx == len(interceptors) { | ||
| return handler | ||
| } | ||
| return func(ctx context.Context, in interface{}) (out interface{}, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are right. I would suggest adding a comment on what that code is meant to do for future reference.
| type StreamHandler func(ctx context.Context, in drpc.Stream) (out interface{}, err error) | ||
|
|
||
| type StreamServerInterceptor func( | ||
| ctx context.Context, stream drpc.Stream, rpc string, handler StreamHandler) (out interface{}, err error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not necessarily suggesting to block on this but IMO interfaces should also help with future needs. I'm fine with the current approach and revisit it if needed.
This change introduces support for server-side interceptors in DRPC. For a deeper understanding of interceptors, refer to the gRPC guide: https://grpc.io/docs/guides/interceptors lthough this functionality logically belongs in the `drpcserver` package, implementing it within `drpcmux` offers a more practical approach, avoiding a substantial refactor.
5d8e4dc to
95e1d1c
Compare
In cockroachdb/drpc#10, we added the DRPC framework level support for interceptors. This PR ports the metrics interceptor to DRPC server. Epic: CRDB-49359 Release note: None
This change introduces support for server-side interceptors in DRPC. For a deeper understanding of interceptors, refer to the gRPC guide: https://grpc.io/docs/guides/interceptors
Although this functionality logically belongs in the
drpcserverpackage, implementing it withindrpcmuxoffers a more practical approach, avoiding a substantial refactor.Fixes: cockroachdb/cockroach#147622